package com.hs.jhzd.repository;

import com.hs.jhzd.entity.ZfYyjlbEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;

@Repository
public interface ZfYyjlbRepository extends JpaRepository<ZfYyjlbEntity, String> {

  List<ZfYyjlbEntity> findByJsbh(String jsbh);

  @Query("select u from ZfYyjlbEntity u where u.jsbh= :jsbh and u.rybh= :rybh and u.yylx<>0")
  List<ZfYyjlbEntity> findByJsbhAndRybh(@Param("jsbh") String jsbh, @Param("rybh") String rybh);

  @Query("select u from ZfYyjlbEntity u where u.jsbh= :jsbh and u.rybh= :rybh and u.yylx=0")
  List<ZfYyjlbEntity> findDoctorByJsbhAndRybh(@Param("jsbh") String jsbh, @Param("rybh") String rybh);
  @Modifying
  @Transactional
  @Query("update ZfYyjlbEntity u set u.zt=:status , u.zxsj=:endTime where u.rybh=:rybh and  u.yysj =:date ")
  int updateDispose(@Param("rybh")String rybh, @Param("date")Date date, @Param("status") Integer status,@Param("endTime")Date endTime);
  @Query(value="select zybh from zf_yyjlb order by zybh DESC limit  1",nativeQuery=true)
  String findZybh();

}
